<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>经营报表</title>
		<link rel="stylesheet" href="dist/css/layui.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/shouy.css" />
	</head>
	<style>
		.top_choice p{float:left;width:50%;font-size: 16px;text-align: center;line-height: 35px ;}
		.top_choice{border:1px solid #2bb6f6 ;width:200px;height: 35px;margin-left:2%;border-radius: 5px;}
		.active{background: #2bb6f6;}
		.active a{color:#FFFFFF}
		.xzselect select{height:35px;font-size: 15px;color:#928c8c;border: 1px solid #e6e6e6;background-color: #FFFFFF;}
		.sy_xftop {padding: 6px 0px;}
		.bx_btn{    float: right;padding-right: 1rem;line-height: 35px;}
		/*退款弹出框*/
		.mask{background: rgba(0,0,0,0.7); width: 100%; height: 100%; position: fixed; left: 0; top: 0; display: none;}
		.phone_box{width: 150px;height:200px; background: white; margin: 16rem auto 0; border-radius: 3px; padding: 4% 5% 5%;}
		.phonetc_bt{color: #000000; font-weight: bold; font-size: 1rem; margin-bottom: .1rem;}
		.phone_box .wz{font-size: .85rem; line-height: normal; margin-bottom: 1.2rem; color: #666666;}
		.phone_box input{border-color: #811588; padding: 10px; color: #000000; font-size: .85rem;}
		.phone_box .yzm_input{width: 52%; float: left;}
		.yzm_btn{width: 45%; float: right; background: #CCCCCC; text-align: center; font-size: .85rem; height: 40px; line-height: 40px; border-radius: 5px; color: #000000;}
		.phone_box input{    line-height: 21px; margin-bottom: 15px;padding: 10px 15px;-webkit-user-select: text;border: 1px solid rgba(0,0,0,.2);border-radius: 3px;outline: 0;background-color: #fff; -webkit-appearance: none;}
		{width: 150px;height:200px; background: white; margin: 9rem auto 0; border-radius: 3px; padding: 4% 5% 5%;}
		.sign_out{float:right;margin:-4rem;width:30px;height: 30px;text-align: center;font-size: 30px;}
		.sy_xftop .layui-form-item .layui-input-inline {width: 100px;}
		.layui-input {font-size: 13px;}
		.layui-form-label{padding: 9px 1px;}
		.sy_xftop .layui-form-label {font-size: 14px; padding-left: 0px; }
		.sy_xfbtn, .sy_jybtn{margin-left:1px}
	</style>
	<body>
		<div class="wrap">
			<div class="sy_header clearfix">
				<div class="sy_hleft">
					<ul class="sy_nav clearfix">
						<li >
							<a href="index.html">
								<div class="iconfont icon-shouyintai"></div>
								<p>工作台</p>
							</a>
						</li>
						<li class="active">
							<a href="orders.html">
								<div class="iconfont icon-saomashouyin"></div>
								<p>订单流水</p>
							</a>
						</li>
						<li>
							<a href="yd.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>预定管理</p>
							</a>
						</li>
						<li>
							<a href="jiaoban.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>交班</p>
							</a>
						</li>
						<li>
							<a href="set.html">
								<div class="iconfont icon-weibiaoti-"></div>
								<p>设置</p>
							</a>
						</li>
					</ul>
				
				</div>
				<div class="sy_hright">
					<div class="sy_shopbox">
						<div class="sy_simg"><img id="toux" src="" style="background-color: #FFFFFF;"></div>
						<div class="sy_sinfo">
							<p class="sy_snam">店名：<span id="sname"></span></p>
							<p>用户：<span id="user"></span></p>
							<p class="exit" onclick="exit()">退出登陆</p>
						</div>
					</div>
				</div>
				
			</div>
			<div class=" clearfix">
				<div class="sy_xftop">
					<div class='top_choice'>
						<p class="tab_d1 active" ><a href="orders.html">账单明细</a></p>
						<p class="tab_d1" ><a href="sum_bill.html">账单汇总</a></p>
					</div>
				</div>
			</div>
			
			<div class="sy_xconbox clearfix">
				<div class="sy_xftop clearfix">
					<div class="layui-form-item">
						<div class="layui-inline">
							<div class="layui-input-inline xzselect" style="margin-left:5px">
								<select name="pay_type" id='pay_type'>
									<option value="">收款渠道</option>
									<option value="">全部</option>
									<option value="3">支付宝</option>
									<option value="2">微信支付</option>
									<option value="1">现金支付</option>
									<option value="5">会员卡支付</option>
									<option value="4">银联</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline xzselect">
								<select name="type" id='jy_type'>
									<option value="">交易类型</option>
									<option value="">全部</option>
									<option value="1">收款</option>
									<option value="4">退款</option>
									<option value="2">充值</option>
									<option value="5">核销</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">订单号</label>
							<div class="layui-input-inline">
								<input type="text" id="sn" placeholder="请输入订单号" name="sn" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">交易时间</label>
							<div class="layui-input-inline" style="width: 120px;">
								<input  ignore type="text" placeholder="yyyy-mm-dd" name="date" id="start_time" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">-</div>
							<div class="layui-input-inline" style="width: 120px;">
								<input  ignore type="text" placeholder="yyyy-mm-dd" name="date1" id="end_time" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline bx_btn">
							<button type="button" id="search" class="sy_jybtn">搜索</button>
							<!--<button type="button" id="export" class="sy_jybtn green">导出报表</button>-->
						</div>

					</div>
				</div>
				<div class="sy_spcenter">
					<table class="layui-table">
						<colgroup>
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col>
						</colgroup>
						<thead>
							<tr>
								<th>订单号</th>
								<th>用户编号</th>
								<th>消费金额</th>
								<th>实际/退款金额</th>
								<th>优惠金额</th>
								<th>房型</th>
								<th>数量</th>
								<th>交易类型</th>
								<th>收款/退款渠道</th>
								<th>收银员</th>
								<th>交易时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="mem_body">
						</tbody>
					</table>
					<div id="demo2" style="text-align: center;"></div>
				</div>
			</div>
		</div>
		<div class="jjbbp_conbox" style="display: none;">
			<div class="jjbbp_item2">
				<div class="jjbbp_bt">房型信息</div>
				<div class="jjbbp_table">
					<table class="layui-table">
						<colgroup>
							<col width="39%">
							<col width="15%">
							<col width="10%">
							<col width="12%">
							<col width="12%">
							<col width="12%">
						</colgroup>
						<thead>
							<tr>
								<th>房型名称</th>
								<th>数量</th>
							</tr>
						</thead>
						<tbody id="goods_tr">
					
						</tbody>
					</table>
				</div>
			</div>
		</div>
		
		
		<div class="mask" id="show_tk">
			<div class="phone_box">
				<p class='sign_out' onclick="javascript:$('#show_tk').hide()"> X </p>
				<p class="wz">可退款金额：<span id='balance'>0</span></p>
				<input type='hidden' id='order_id'>
				<p><input type="text" name="tk_money" id="tk_money" placeholder="请输入退款金额" autocomplete="off"></p>
				<p><input type="password" name="pwd" id="pwd" placeholder="请输入您的操作密码" autocomplete="off"></p>
				<p><input type="text" name="msg" id="msg" placeholder="备注" autocomplete="off">
				</p>
				<p><button type="button" id="tk_bun" class="sy_jybtn" onclick="tk_bun()">确认</button></p>
			</div>
		</div>
		
		
		<script type="text/javascript" src="dist/jquery-1.11.0.min.js"></script>
		<script src="dist/layui.all.js"></script>
		<script src="dist/json2.js"></script>
		<script type="text/javascript" src="js/app.js"></script>
		<script type="text/javascript" src="js/common.js?1=1"></script>
		<script>
			$(".top_choice p").click(function(){
				$(".active").removeClass("active");
				$(this).addClass("active");
			})
			
			if(!document.querySelectorAll) {
				document.querySelectorAll = function(selectors) {
					var style = document.createElement('style'),
						elements = [],
						element;
					document.documentElement.firstChild.appendChild(style);
					document._qsa = [];

					style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
					window.scrollBy(0, 0);
					style.parentNode.removeChild(style);

					while(document._qsa.length) {
						element = document._qsa.shift();
						element.style.removeAttribute('x-qsa');
						elements.push(element);
					}
					document._qsa = null;
					return elements;
				};
			}

			if(!document.querySelector) {
				document.querySelector = function(selectors) {
					var elements = document.querySelectorAll(selectors);
					return(elements.length) ? elements[0] : null;
				};
			}

			
			
			$(function() {
				load_dt();
			})
			$("#search").click(function() {
				var sk_type = $('#pay_type').val();
				var type = $('#jy_type').val();
				var sn = $("#sn").val();
				var start_time = $("#start_time").val();
				var end_time = $("#end_time").val();
				load_dt(1, sn, start_time, end_time,sk_type,type)

			})
			$("#export").click(function() {
				var begin = $("#start_time").val();
				var end = $("#end_time").val();
				var str = "&begin_time=" + begin + "&end_time=" + end;
				window.location.href = APP.api_url + "sy/export?chain_id=" + getValue("chain_id") + str;
			})

			function load_dt(page, sn, start_time, end_time,pay_type,type) {
				layui.use(['laypage', 'layer'], function() {
					var laypage = layui.laypage,
						layer = layui.layer;
					var index = layer.load(1, {
						shade: [0.1, '#fff'] //0.1透明度的白色背景
					});
					$.ajax({
						type:'post',
						url: APP.api_url + "Sy/get_reports",
						data: {
							store_id:getValue("store_name_id"),
							chain_id:getValue("chain_id"),
							page: page,
							pay_type:pay_type,
							type:type,
							sn: sn,
							start_time: start_time,
							end_time: end_time,
							app_id	:APP.app_id,
							time:Date.parse( new Date()),
							id:getValue('id'),
							login_time:getValue('login_time')
						},
						success: function(dt) {
							var mems = dt.list;
							var count = dt.count;
							if(mems) {
								var tr = "";
								for(var m in mems) {
									var log = mems[m];
									var status = "未完成";
									if(log.state == 2) {
										status = "已完成";
									}
									
									var room_name = log['room_name']==null?'':log['room_name'];
									var room_num = log['room_num']==null?'':log['room_num'];
									
									var type = "收款";
									if(log['type'] == 1) {
										type = '收款';
									} else if(log['type'] == 2) {
										type = '充值';
									} else if(log['type'] == 3) {
										type = '客房预订';
									} else if(log['type'] == 4) {
										type = '退款';
									} else if(log['type'] == 5) {
										type = '核销';
										room_num = log['hx_total'];
									} else if(log['type']==6){
										type = '记账';
									} else if(log['type']==7){
										type='餐厅预订';
									} else if(log['type']==8){
										type='桌面收银扫一扫';
									}
									var pay_type = "现金";
									if(log['pay_type'] == 2) {
										pay_type = "微信";
									}else if(log['pay_type'] == 3) {
										pay_type = "支付宝";
									}else if(log['pay_type'] == 4){
										pay_type = "其他";
									}else if(log['pay_type']==5){
										pay_type='会员卡';
									}else if(log['pay_type'] ==6){
										pay_type = '卡券';
									}else if(log['pay_type']==7){
										pay_type = '到店';
									}else if(log['pay_type']==8){
										pay_type = '银行卡'
									}
									
									tk = ""
									if(log['is_tk']==0 && log['type']!==6){//退款不包括记账
										tk='<a href="javascript:show_tk('+log['id']+','+log['balance']+')" class="layui-btn layui-btn-mini" lay-event="edit">退款</a>';
									}
									if(log['is_tk']==0 && log['pay_type']==6){
//										tk='<a href="javascript:show_tq('+log['id']+','+log['balance']+')" class="layui-btn layui-btn-mini" lay-event="edit">退券</a>';
										tk='';
									}
									
									balance = log['balance'];
									if(log['type']==4){
										balance =log['tk_money'];
									}
									var yh_balance = (log['origin_price']-log['balance']).toFixed(2);
									tr += '<tr>' +
										'<td >' + log['order_sn'] + '</td>' +
										'<td>' + log['user_id'] + '</td>' +
										'<td>' + log['origin_price'] + '</td>' +
										'<td>' + balance + '</td>' +
										'<td>' + yh_balance + '</td>' +
										'<td><a style="color:#169bd5" href="javascript:show_info('+log['id']+')">' + room_name + '</a></td>' +
										'<td>' + room_num + '</td>' +
										'<td>' + type + '</td>' +
										'<td>' + pay_type + '</td>' +
										'<td>'+log['emp_name']+'</td>' +
										'<td>' + log['add_time'] + '</td>' +
										'<td><a href="#" onclick="print_order(' + log['id'] + ')" class="layui-btn layui-btn-mini" lay-event="edit">打印</a><br><br>' + tk + '</td>' +
										'</td>'+
										'</tr>';
								}
								$("#mem_body").html(tr);
								layer.close(index);
								//调用分页
								laypage.render({
									elem: 'demo2',
									count: count,
									limit: 4,
									jump: function(obj, first) {
										//模拟渲染
										var curr = obj.curr;
										if(!first) {
											//layer.msg('第 '+ obj.curr +' 页');
											get_reports(curr);
										}
									}
								});
							}

						}
					})

				});

			}

			function get_reports(page) {
				$.ajax({
					type:'post',
					url: APP.api_url + "Sy/get_reports",
					data: {
						store_id: getValue("store_name_id"),
						chain_id:getValue("chain_id"),
						page: page,
						start_time:$("#start_time").val(),
						end_time:$("#end_time").val(),
						app_id	:APP.app_id,
						time:Date.parse( new Date()),
						id:getValue('id'),
						login_time:getValue('login_time')
					},
					success: function(dt) {
						var mems = dt.list;
						if(mems) {
							var tr = "";
							for(var m in mems) {
									var log = mems[m];
									var status = "未完成";
									if(log.state == 2) {
										status = "已完成";
									}
									
									var room_name = log['room_name']==null?'':log['room_name'];
									var room_num = log['room_num']==null?'':log['room_num'];
									
									var type = "收款";
									if(log['type'] == 1) {
										type = '收款';
									} else if(log['type'] == 2) {
										type = '充值';
									} else if(log['type'] == 3) {
										type = '客房预订';
									} else if(log['type'] == 4) {
										type = '退款';
									} else if(log['type'] == 5) {
										type = '核销';
										room_num = log['hx_total'];
									} else if(log['type']==6){
										type = '记账';
									} else if(log['type']==7){
										type='餐厅预订';
									} else if(log['type']==8){
										type='桌面收银扫一扫';
									}
									var pay_type = "现金";
									if(log['pay_type'] == 2) {
										pay_type = "微信";
									}else if(log['pay_type'] == 3) {
										pay_type = "支付宝";
									}else if(log['pay_type'] == 4){
										pay_type = "其他";
									}else if(log['pay_type']==5){
										pay_type='会员卡';
									}else if(log['pay_type'] ==6){
										pay_type = '卡券';
									}else if(log['pay_type']==7){
										pay_type = '到店';
									}else if(log['pay_type']==8){
										pay_type = '银行卡'
									}
									
									tk = ""
									if(log['is_tk']==0 && log['type']!==6){//退款不包括记账
										tk='<a href="javascript:show_tk('+log['id']+','+log['balance']+')" class="layui-btn layui-btn-mini" lay-event="edit">退款</a>';
									}
									if(log['type']!==4 && log['pay_type']==6){
//										tk='<a href="javascript:show_tq('+log['id']+','+log['balance']+')" class="layui-btn layui-btn-mini" lay-event="edit">退券</a>';
										tk='';
									}
									
									balance = log['balance'];
									if(log['type']==4){
										balance =log['tk_money'];
									}
									var yh_balance = (log['origin_price']-log['balance']).toFixed(2);
									tr += '<tr>' +
										'<td >' + log['order_sn'] + '</td>' +
										'<td>' + log['user_id'] + '</td>' +
										'<td>' + log['origin_price'] + '</td>' +
										'<td>' + balance + '</td>' +
										'<td>' + yh_balance + '</td>' +
										'<td><a style="color:#169bd5" href="javascript:show_info('+log['id']+')">' + room_name + '</a></td>' +
										'<td>' + room_num + '</td>' +
										'<td>' + type + '</td>' +
										'<td>' + pay_type + '</td>' +
										'<td>'+log['emp_name']+'</td>' +
										'<td>' + log['add_time'] + '</td>' +
										'<td><a href="#" onclick="print_order(' + log['id'] + ')" class="layui-btn layui-btn-mini" lay-event="edit">打印</a><br><br>' + tk + '</td>' +
										'</td>'+
										'</tr>';
								}
							$("#mem_body").html(tr);
						}
					}
				})
			}
			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;
				//日期
				laydate.render({
					elem: '#start_time'
				});
				laydate.render({
					elem: '#end_time'
				});

			});
			
			//退款
			function show_tk(id,balance){
				$('#balance').text(balance);
				$('#order_id').val(id);
				$('#show_tk').show();
			}
			
			//退款发送请求
			function tk_bun(){
				var balance= $('#balance').text();
				var tk_money = $("#tk_money").val();
				var pwd = $('#pwd').val();
				var msg = $('#msg').val();
				if(tk_money==''){
					layer.msg("退款金额不可为空");
					return;
				}
				if(pwd==''){
					layer.msg("请输入操作密码");
					return;
				}
				if(Number(tk_money)>Number(balance)){
					layer.msg("退款金额不可大于用户实际支付金额");
					return;
				}
				$.ajax({
					type:'post',
					url: APP.api_url + "Sy/refund",
					data: {
						order_id:$('#order_id').val(),
						tk_money:tk_money,
						msg:msg,
						pwd:pwd,
						staff_id:getValue('id')
					},
					success: function(data) {
						if(data.code==200){
							$('#balance').text('');
							$("#tk_money").val('');
							$('#pwd').val('');
							$('#msg').val('');
							$('#show_tk').hide();
							jz_common(data,tk_money,1);
							load_dt();
						}else{
							layer.msg(data.msg);
						}
					}
				})
			}
			
			
			//查询所有核销房型和数量
			function show_info(id){
				var index = layer.load(1, {
						shade: [0.1, '#fff'] //0.1透明度的白色背景
				});
				$("#goods_tr").html("");
				$.ajax({
					url: APP.api_url + "Sy/get_roominfo",
					data: {
						order_id:id,
						app_id: APP.app_id,
					},
					success: function(data) {
						var room_info=data['room_info'];
						if(room_info&&room_info.length>0){
							var html_tr="";
							for(var i=0;i<room_info.length;i++){
								var gd=room_info[i];
								html_tr+='<tr>'+
								'<td>'+gd.room_name+'</td>'+
								'<td>'+gd.num+'</td>'+
								'</tr>';
							}
							$("#goods_tr").html(html_tr);
						}
						layer.close(index);
						layer.open({
							title: '房型详情',
							shadeClose: false,
							shade: 0.8,
							btn: false,
							area: ['550px', '450px'],
							content: $(".jjbbp_conbox").html()
						});
					}
				})
			}
			
			
//			退券
			function show_tq(){
				
			}
			
			
		</script>

	</body>

</html>